-
Notifications
You must be signed in to change notification settings - Fork 245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement specialization constant support in numthreads / local_size #5963
Implement specialization constant support in numthreads / local_size #5963
Conversation
cde9d98
to
1862056
Compare
1862056
to
1c7b6cc
Compare
I've now tested this in a real Vulkan program in a couple of different contexts, and this feature seems to now work correctly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a test for this feature?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. I wish there is a cleaner way to add this feature, but what is implemented in this PR is probably the easiest path forward. If I understand the code correctly, this implementation won't allow something like [numthreads(specConst+1, 1, 2)]
, right?
It currently doesn't allow doing math on the specialization constant, because I'm fairly sure that that can't be expressed in SPIR-V. I'll fix that compiler warning later today, I've been developing on Linux only so I guess MSVC errors are to be expected. |
Oh no... Sorry for the spam, I made a mistake. I didn't mean to add tangent-vector & expipiplus1 as reviewers, but something went really wrong with merging master into this branch... Anyway, I fixed one more issue with this PR (thread group sizes in reflection were busted), and re-ran tests locally on a Linux and Windows machine. I think it should be OK now. (previously, all tests were showing "failed" due to #6050) |
7a2393a
to
5544737
Compare
It seems that this implementation does not cover setting the wave size via constants e.g., [vk::constant_id(0)] const int CONST_VAR = 1;
[WaveSize(CONST_VAR, 1, 1)] Edit: Ok I am confused, there is also a |
@fknfilewalker Is there a platform where you can set wave size / subgroup size with a specialization constant? With a quick scan through the SPIR-V spec, I couldn't find an instruction that would allow for that. AFAIK numthreads() and NumThreads() should be equivalent (at least they map to the same AST node in |
With |
Huh, odd, I can't replicate that. |
Sorry I was wrong, |
No problem! Btw, about the WaveSize thing: "Wave" is Subgroup in Khronos terminology, you can read more about that feature here. Some hardware allows you to select how wide the "Wave"/subgroup is (IIRC at least AMD RDNA3 has 32/64 options and Intel Arc GPUs has even more alternatives). |
Interesting that AMD and Intel can configure this size. I think for SPIRV this is set via the execution mode 35. |
Adds support for using SPIR-V specialization constants in
numthreads
:Also adds support in GLSL mode:
Similar to the
local_size_x_id
feature from GLSL, this allows users to generate shader permutations with different work group shapes / thread counts after the shader has already been compiled to SPIR-V.Currently, this works with the SPIR-V (using
LocalSizeId
execution mode) and GLSL (usinglocal_size_{x,y,z}_id
) targets. I'm not sure if there even is anything that could be done for the other targets, other than to just present diagnostics about this feature not being supported there.